package com.nuoniu.sibanyun.config;

import com.nuoniu.sibanyun.entity.SysUser;
import com.nuoniu.sibanyun.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private ISysUserService  sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser user = sysUserService.findByUserName(username);
        if(user == null){
            throw new UsernameNotFoundException(username);
        }
        return new JwtUser(user);
    }

}
